//
//  OrderCenterStore.m
//  NewPro
//
//  Created by RYX on 2018/10/22.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "OrderCenterStore.h"
#import "OrderCenterParametersModel.h"
#import "OrderCenterModel.h"

@implementation OrderCenterStore

#pragma mark - 获取订单列表
- (void)getOrderListWithParametersModel:(OrderCenterParametersModel *)parametersModel Success:(void(^)(NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/order/getOrderType",IP];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    
    [dic setObject:parametersModel.customId forKey:@"customId"];
    
    if (parametersModel.flag.length > 0) {
        
        [dic setObject:parametersModel.flag forKey:@"flag"];
    }
    
    if (parametersModel.isPay.length > 0) {
        
        [dic setObject:parametersModel.isPay forKey:@"isPay"];
    }
    
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            
            NSArray *listArr = [OrderCenterModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"items"]];
            
            success(listArr);
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
       
        failure(error);
    }];
}

#pragma mark - 取消订单
- (void)deleteOrderWithId:(NSString *)orderId Success:(void(^)(void))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/order/cancelOrder",IP];
    
    NSDictionary *dic = @{
                          @"orderId":orderId
                          };
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            
            success();
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
       
        failure(error);
    }];
    
}

#pragma mark - 确认收货
- (void)onSureReciveGoodsWithId:(NSString *)orderId Success:(void(^)(void))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/order/confirmOrder",IP];
    
    NSDictionary *dic = @{
                          @"orderId":orderId
                          };
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            
            success();
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        
        failure(error);
    }];
    
}
@end
